package com.db.controller;

import com.db.common.pojo.TreeNode;
import com.db.pojo.SysMenu;
import com.db.service.SysMenuService;
import com.db.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/menu/")
public class SysMenuController {

	@Autowired
	private SysMenuService sysMenuService;

	@RequestMapping("doFindObjects")
	public SysResult doFindObjects() {
		List<SysMenu> list = sysMenuService.findObjects();
		return new SysResult(list);
	}

	@RequestMapping("doDeleteObject")
	public SysResult doDeleteObject(Integer id) {
		sysMenuService.deleteById(id);
		return new SysResult("delete ok");
	}

	@RequestMapping("doSaveObject")
	public SysResult doSaveObject(SysMenu sysMenu) {
		sysMenuService.insertObject(sysMenu);
		return new SysResult("save ok");
	}

	@RequestMapping("doFindZtreeMenuNodes")
	public SysResult doFindZtreeMenuNodes() {
		List<TreeNode> treeNodes = sysMenuService.findTree();
		return new SysResult(treeNodes);
	}

	@RequestMapping("doUpdateObject")
	public SysResult doUpdateObject(SysMenu sysMenu) {
		sysMenuService.updateObject(sysMenu);
		return new SysResult("update ok");
	}
}
